package com.yingpai.fitness.dvp_2_0.main.activity.mine;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.yingpai.fitness.R;
import com.yingpai.fitness.base.BaseResponse;
import com.yingpai.fitness.dvp_2_0.common.activity.CommonActivity;
import com.yingpai.fitness.dvp_2_0.common.finalokgo.callback.Callback;
import com.yingpai.fitness.dvp_2_0.common.finalokgo.request.RequestType;
import com.yingpai.fitness.dvp_2_0.common.util.SharedPreferencesHelp;
import com.yingpai.fitness.dvp_2_0.common.util.constant.Contacts;
import com.yingpai.fitness.dvp_2_0.main.util.constant.Constant;
import com.yingpai.fitness.dvp_2_0.main.util.constant.Url;
import com.yingpai.fitness.dvp_2_0.main.widget.FeedEditTextWithCountRelativeLayout;
import com.yingpai.fitness.entity.wx.TokenBean;

import butterknife.BindView;
import butterknife.OnClick;


public class FeedBackActivity extends CommonActivity {


    @BindView(R.id.feed_back_relative_layout_et)
    FeedEditTextWithCountRelativeLayout feedBackRelativeLayoutEt;
    private TokenBean token;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusFlag(Contacts.NORMAL_STATUS);
        setContentView(R.layout.feed_back_activity);
    }

    @Override
    protected void initView() {
        setTitle("意见反馈");

        token = ((TokenBean) (SharedPreferencesHelp.getBean(Constant.TOKENBEAN)));

        String title = getIntent().getStringExtra("title");
        String nickname = getIntent().getStringExtra("nikename");
        if (title != null && !TextUtils.isEmpty(title)) {
            feedBackRelativeLayoutEt.setInputContent("标题：" + title + "\n" + "作者：" + nickname + "\n" + "举报原因：");
        }

        feedBackRelativeLayoutEt.getEditText().setSelection(feedBackRelativeLayoutEt.getInputContent().toString().length());
    }

    @Override
    protected void initData() {

    }

    @Override
    @OnClick({R.id.feed_back_submit_bt})
    public void onViewClicked(View view) {
        super.onViewClicked(view);
        switch (view.getId()) {
            case R.id.feed_back_submit_bt:
                if (!TextUtils.isEmpty(feedBackRelativeLayoutEt.getInputContent())) {
                    showDialog(this, null);
                    HttpParams httpParams = new HttpParams();
                    httpParams.put("customerId", token.getId());
                    httpParams.put("feedback", feedBackRelativeLayoutEt.getInputContent().toString().trim());
                    finalOkGo.request(RequestType.POST, Contacts.HOST_SERVER + Url.FEED_BACK_SAVE, httpParams, Url.FEED_BACK_SAVE, new Callback<BaseResponse>() {
                        @Override
                        public void onSuccess(BaseResponse baseResponse) {
                            dismissDialog();
                            if (baseResponse.getResult().equals(Constant.REQUEST_SUCCESS)) {
                                showToast("提交成功");
                                finishActivity();
                            } else {
                                showToast(baseResponse.getMsg());
                            }
                        }

                        @Override
                        public void onError(Response<String> response) {
                            super.onError(response);
                            dismissDialog();
                        }
                    });
                } else {
                    showToast("反馈内容不能为空");
                }

                break;
        }
    }
}
